package com.yuchting.dinneronline.client.common;

import com.google.gwt.json.client.JSONObject;

public class User {

	private String m_name = "";
		
	private String m_pass = "";
	
	private double m_remainMoney = 0;
	
	private double m_totalPay = 0;
	
	// gets and sets function
	//
	public String getName(){return m_name;}
	public void setName(String _name){m_name = _name;}
	
	public String getPass(){return m_pass;}
	public void setPass(String _pass){m_pass = _pass;}
	
	public double getRemainMoney(){return m_remainMoney;}
	public void setRemainMoney(double _money){m_remainMoney = _money;}
	
	public double getTotalPay(){return m_totalPay;}
	public void setTotalPay(double _totalPay){m_totalPay = _totalPay;}
	
	public JSONObject toJSON(){
		
		YuchJSONObject t_result = new YuchJSONObject();
		try{
			t_result.put("name",m_name);
			t_result.put("pass",m_pass);
			t_result.put("remain",m_remainMoney);
			t_result.put("total",m_totalPay);
		}catch(Exception e){
			System.err.println("User toJSON Error:");
			e.printStackTrace(System.err);
		}
		
		return t_result.m_json;
	}
	
	public User cloneUser(){
		User u = new User();
		u.fromJSON(new YuchJSONObject(toJSON()));
		return u;
	}
	
	public void fromJSON(YuchJSONObject _json){
		try{
		
			m_name 			= _json.getString("name");
			m_pass 			= _json.getString("pass");
			m_remainMoney 	= _json.getDouble("remain");
			m_totalPay 		= _json.getDouble("total");
			
		}catch(Exception e){
			System.err.println("User fromJSON Error:");
			e.printStackTrace(System.err);
		}
	}
}
